/**
* @mxmlc -output=bin/assets/modules/preload.swf -external-library-path+=lib/library.swc -debug=false -noplay
*/
package preload 
{
	import org.airmvc.View;
	import ui.preload.PreLoadUI;
	
	/**
	 * 预加载视图
	 * @author WLDragon 2014-02-24
	 */
	public class PreLoadV extends View 
	{
		
		public function PreLoadV(){}
		
		override public function init():void 
		{			
			ui = new PreLoadUI();
			addChild(ui);
		}
		
		override protected function addListeners():void 
		{
			receive(PreLoadC.SHOW_OR_HIDE, handleShowOrHide);
			receive(PreLoadC.UPDATE_PROGRESS, handleUpdate);
			receive(PreLoadC.DISPOSE,handleDispose);
		}
		
		private function handleUpdate(message:String,value:Number):void 
		{
			ui.labText.text = message;
			ui.prgBar.value = value;
		}

		private function handleShowOrHide():void 
		{
			if (parent)
			{
				Lyr.ui.removeChild(this);
			}
			else
			{
				Lyr.ui.addChild(this);
			}
		}
		
		private function handleDispose():void
		{
			if (parent)
				Lyr.ui.removeChild(this);
				
			ui = null;
			cancelReceive(PreLoadC.DISPOSE);
			cancelReceive(PreLoadC.SHOW_OR_HIDE);
			cancelReceive(PreLoadC.UPDATE_PROGRESS);
		}
		
		private var ui:PreLoadUI;
	}
	
}